function [data stats] = calcClassifierStats(data, classifier, holdout_cam)

get_sets = true;
if ~isempty(holdout_cam)
    data = data(holdout_cam, :);
    get_sets = false;
end

load_settings;
ppl_preds = [];
ppl_dv = [];
bg_dv = [];

feature_size = size(data(1,1).ppl_hogs(1,:));
bg_preds = [];
avg_ppl_hog = zeros(feature_size);
avg_bg_hog = zeros(feature_size);
num_ppl_hogs = 0;
num_bg_hogs = 0;

if get_sets
   [ test_prefs test_sets , ~, ~, ~, ~, ~, ~, ~ ] = splitDataTTV(data);
   for ix = 1:length(test_sets)
       [ preds, ~ ] = eval_baseline(classifier, test_sets{ix}, test_prefs{ix}, settings);
       for jx = 1:length(test_prefs{ix})
           if test_prefs{ix}(jx) == 1
                avg_ppl_hog = avg_ppl_hog + test_sets{ix}(jx,:);
                num_ppl_hogs = num_ppl_hogs + 1;
                ppl_preds = [ppl_preds preds.p(jx)];
                ppl_dv = [ppl_dv preds.dv(jx)];
           else
                avg_bg_hog = avg_bg_hog + test_sets{ix}(jx,:);
                num_bg_hogs = num_bg_hogs + 1;
                bg_preds = [bg_preds preds.p(jx)];
                bg_dv = [bg_dv preds.dv(jx)];
           end
       end
   end
   ppl_preds = ppl_preds';
   bg_preds = bg_preds';
    
else
    for ix = 1:size(data,1)
        for jx = 1:size(data,2)
            if ~isempty(data(ix,jx).cam_id)
                disp(['calcClassifierStats: calculating predictions for cam: ' num2str(data(ix,jx).cam_id) ' and img: ' num2str(data(ix,jx).day) num2str(data(ix,jx).hour)]);
                [ppl_new, ~] = eval_baseline(classifier, data(ix,jx).ppl_hogs, ones(size(data(ix,jx).ppl_hogs,1),1), settings);
                [bg_new, ~] = eval_baseline(classifier, data(ix,jx).bg_hogs, -ones(size(data(ix,jx).bg_hogs,1),1), settings);
                
                avg_ppl_hog = avg_ppl_hog + sum(data(ix,jx).ppl_hogs);
                num_ppl_hogs = num_ppl_hogs + size(data(ix,jx).ppl_hogs, 1);
                
                avg_bg_hog = avg_bg_hog + sum(data(ix,jx).bg_hogs);
                num_bg_hogs = num_bg_hogs + size(data(ix,jx).bg_hogs, 1);
                
                ppl_preds = [ppl_preds; ppl_new.p];
                bg_preds = [bg_preds; bg_new.p];
                bg_dv = [bg_dv; ppl_new.dv];
                ppl_dv = [ppl_dv; bg_new.dv];
                
                data(ix,jx).bg_preds = bg_new;
                data(ix,jx).ppl_preds = ppl_new;
            end
        end
    end
end

stats.ppl_predictions = ppl_preds;
stats.bg_predictions = bg_preds;
stats.ppl_acc = mean(ppl_preds == ones(size(ppl_preds)));
stats.bg_acc = mean(bg_preds == -ones(size(bg_preds)));
stats.acc = mean([ppl_preds; bg_preds] == [ones(size(ppl_preds)); -ones(size(bg_preds))]);
stats.mean_ppl_hog = avg_ppl_hog./num_ppl_hogs;
stats.mean_bg_hog = avg_bg_hog./num_bg_hogs;
stats.mean_hog = (avg_ppl_hog+avg_bg_hog)./(num_ppl_hogs+num_bg_hogs);
stats.weight = classifier.model(1:end-1)' ;
stats.ppl_dv = ppl_dv;
stats.bg_dv = bg_dv;

pos = stats.weight;
pos(stats.weight<0) = 0;
pos = hogToIm(single(pos));
neg = stats.weight;
neg(stats.weight>0) = 0;
neg = hogToIm(single(-neg));

img = zeros([size(neg) 3]);
img(:,:,2) = pos;
img(:,:,1) = neg;
img(:,:,3) = neg;
% imshow(img);
% title('Weight');
stats.img_of_weight = img;

end